﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace LFramework.Data
{
    public interface IDBHelper
    {
        /// <summary>
        /// 执行SQL返回首行首列
        /// </summary>
        /// <param name="SQL">sql</param>
        /// <returns>影响行数</returns>
        object ExecuteScalar(string SQL);


        /// <summary>
        /// 执行SQL返回首行首列
        /// </summary>
        /// <param name="SQL">sql</param>
        /// <param name="timeOut">超时时间</param>
        /// <returns>影响行数</returns>
        object ExecuteScalar(string SQL, int timeOut);


        /// <summary>
        /// 执行SQL
        /// </summary>
        /// <param name="SQL">sql</param>
        /// <returns>影响行数</returns>
        int ExecuteSQL(string SQL);


        /// <summary>
        /// 执行SQL
        /// </summary>
        /// <param name="SQL">sql</param>
        /// <param name="timeOut">超时时间</param>
        /// <returns>影响行数</returns>
        int ExecuteSQL(string SQL, int timeOut);


        /// 执行SQL(事务)
        /// </summary>
        /// <param name="SQL">sql</param>
        /// <returns>影响行数</returns>
        int ExecuteSQL_InTrans(string SQL);


        /// 执行SQL(事务)
        /// </summary>
        /// <param name="SQL">sql</param>
        /// <param name="timeOut">超时时间</param>
        /// <returns>影响行数</returns>
        int ExecuteSQL_InTrans(string SQL, int timeOut);


        /// <summary>
        /// 执行参数式 SQL 
        /// </summary>
        /// <param name="SQL">sql</param>
        /// <param name="paras">参数</param>
        /// <returns>影响行数</returns>
        int ExecuteSQL(string SQL, Array paras);


        /// <summary>
        /// 执行参数式 SQL 
        /// </summary>
        /// <param name="SQL">sql</param>
        /// <param name="paras">参数</param>
        /// <param name="timeOut">超时时间</param>
        /// <returns>影响行数</returns>
        int ExecuteSQL(string SQL, Array paras, int timeOut);


        /// <summary>
        /// 执行SQL
        /// </summary>
        /// <param name="SQL">sql</param>
        /// <returns>影响行数</returns>
        int ExecuteSQL_InTrans(string SQL, Array paras);


        /// <summary>
        /// 执行SQL
        /// </summary>
        /// <param name="SQL">sql</param>
        /// <param name="timeOut">超时时间</param>
        /// <returns>影响行数</returns>
        int ExecuteSQL_InTrans(string SQL, Array paras, int timeOut);


        /// <summary>
        /// 根据sql读取DataTable数据集
        /// </summary>
        /// <param name="SQL">sql</param>
        /// <returns>DataTable数据集</returns>
        DataTable QueryForDataTable(string SQL);


        /// <summary>
        /// 根据sql读取DataTable数据集
        /// </summary>
        /// <param name="SQL">sql</param>
        /// <param name="timeOut">超时时间</param>
        /// <returns>DataTable数据集</returns>
        DataTable QueryForDataTable(string SQL, int timeOut);


        /// <summary>
        /// 查询记录数
        /// </summary>
        /// <param name="SQL">sql</param>
        /// <returns>记录数</returns>
        int QueryForCount(string SQL);


        /// <summary>
        /// 查询记录数
        /// </summary>
        /// <param name="SQL">sql</param>
        /// <param name="timeOut">超时时间</param>
        /// <returns>记录数</returns>
        int QueryForCount(string SQL, int timeOut);

        /// <summary>
        /// 批量执行插入
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="dt">数据</param>
        void ExecuteBulkCopy(string tableName, DataTable dt);

        /// <summary>
        /// 获取表的列名
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <returns>列名集合，例如 [GoodsCode,GoodsName,SalePrice] </returns>
        string GetTableColumns(string tableName);

        /// <summary>
        /// 打开数据库连接
        /// </summary> 
        /// <returns>连接状态</returns>
        ConnectionState OpenConnection();

        /// <summary>
        /// 关闭数据库连接
        /// </summary>
        /// <returns>连接状态</returns>
        ConnectionState CloseConnection();

        /// <summary>
        /// 测试数据库连接
        /// </summary>
        /// <returns>成功/失败</returns>
        bool TestConnection();
    }
}
